from appium import webdriver
import time
import base64
import sys
import io


sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf8')
driver_cap = {}
driver_cap['platformName'] = 'Android'
driver_cap['platformVersion'] = '7.1'
driver_cap['deviceName'] = '192.168.176.102:5555'
driver_cap['appPackage'] = 'com.android.settings'
driver_cap['appActivity'] = '.Settings'

driver = webdriver.Remote('http://localhost:4723/wd/hub', driver_cap)

data = str(base64.b64encode('Hello Appnium'.encode('utf-8')), 'utf-8')
driver.push_file('/sdcard/test.txt', data)

data1 = driver.pull_file('sdcard/test.txt')
print(str(base64.b64decode(data1), 'utf-8'))
print(driver.page_source)
# driver.background_app(5)

# driver.find_element_by_id('com.android.settings:id/search').click()
# time.sleep(3)
# driver.find_element_by_class_name('android.widget.ImageButton').click()
# time.sleep(3)
# driver.find_element_by_xpath('//*[contains(@class,"android.widget.LinearLayout")]').click()

# eles = driver.find_elements_by_id('android:id/title')
# eles = driver.find_elements_by_class_name('android.widget.LinearLayout')
# print(eles)
# print(len(eles))
# print(type(eles))

# time.sleep(3)
# driver.quit()

